home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Modules / phil.em < prev    next >
Lisp/Scheme  |  1992-10-06  |  2KB  |  72 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                           ;;
  3. ;;  EuLisp Module                     Copyright (C) University of Bath 1991  ;;
  4. ;;                                                                           ;;
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.  
  7. (defmodule phil
  8.   (standard0 ellis)
  9. ;;  (lists
  10. ;;   list-operators
  11. ;;   extras
  12. ;;   streams
  13. ;;   arith
  14. ;;
  15. ;;   linda-base
  16. ;;   linda-tabs
  17. ;;   linda
  18. ;;   vectors
  19. ;;   threads
  20. ;;   semaphores) 
  21. ()
  22.  
  23.   ;; Our linda pool...
  24.  
  25.   (deflocal phil-pool (make-local-pool))
  26.  
  27.   ;; and scheduler
  28.   (deflocal phil-scheduler (make-local-linda-scheduler))
  29.  
  30.   ;; Parameter...
  31.  
  32.   (deflocal Num 6)
  33.  
  34.   ;; Philosopher process...
  35.  
  36.   (defun phil (i)
  37.     (tilnil
  38.       (prin i) (print " is thinking")
  39.       (linda-in phil-pool (tuple 'room-ticket))
  40.       (print "GOT TICKET")
  41.       (linda-in phil-pool (tuple 'chopstick i))
  42.       (print "GOT CS 1")
  43.       (linda-in phil-pool (tuple 'chopstick (remainder (+ i 1) Num)))
  44.       (prin i) (print " is pigging out")
  45.       (linda-out phil-pool (tuple 'chopstick i))
  46.       (linda-out phil-pool (tuple 'chopstick (remainder (+ i 1) Num)))
  47.       (linda-out phil-pool (tuple 'room-ticket))
  48.       (thread-reschedule)))
  49.  
  50.   (defun init () (init-aux Num))
  51.  
  52.   (defun init-aux (n)
  53.     (if (= n 0) 
  54.       (progn
  55.     (prin "init complete for ") (prin Num) (print " philosophers")
  56. ;;    (linda-in phil-pool (tuple 'zombie))
  57.     (thread-suspend))
  58.       (progn
  59.     (linda-out phil-pool (tuple 'chopstick (- n 1)))
  60.     (prin "phil ") (prin (- n 1))
  61.     (prin " is ") (print (linda-start phil-scheduler phil (- n 1)))
  62.     (if (< (- n 1) (- Num 1)) 
  63.       (linda-out phil-pool (tuple 'room-ticket))
  64.       nil)
  65.     (init-aux (- n 1)))))
  66.  
  67.  
  68. )
  69.     
  70.     
  71.     
  72.